//封装axios
import axios from "axios";
import qs from "qs";
import { Loading } from "element-ui";
var host;
//判断是开发环境还是生产环境
if (process.env.NODE_ENV == "development") {
    host = "https://api-hmugo-web.itheima.net/api/public/v1/"
} else {
    host = "https://api-hmugo-web.itheima.net/api/public/v1/"
}
//创建axios实例
const instance = axios.create({
    baseURL: host,
    timeout: 5000,
})
var loading = null;
//强求拦截器
instance.interceptors.request.use(res => {
        //开启loading
        loading = Loading.service({
            lock: true,
            text: 'Loading',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
        })
        if (res.method.toLocaleLowerCase == "post") {
            res.data = qs.stringify(res.data)
        }
        return res
    }, err => {
        return Promise.reject(err)
    })
    //响应拦截器
instance.interceptors.response.use(res => {
    loading.close();
    return res.data
}, err => {
    return Promise.reject(err)
})
export default instance;